package service

import (
	"bms/dao"
	"bms/model"
)

func GetBook() []*model.Book {
	books := dao.GetBook()
	return books
}
func GetBookByPage(currentPage int64) *model.Page {
	page := dao.GetBookByPage(currentPage)
	return page
}
func GetBookByTitleOrAuthor(currentPage int64, title, author string) *model.Page {
	page := dao.GetBookByTitleOrAuthor(currentPage, title, author)
	return page
}

func BorrowBook(bookId int64) (*model.Book, error) {
	book, err := dao.BorrowBook(bookId)
	if err != nil {
		return nil, err
	}
	return book, nil
}

func QueryBookById(bookId int64) *model.Book {
	book := dao.QueryBookById(bookId)
	return book
}

func AddNewBook(book *model.Book) error {
	err := dao.AddNewBook(book)
	if err != nil {
		return err
	}
	return nil
}

func ReviseBook(book *model.Book) error {
	err := dao.ReviseBook(book)
	if err != nil {
		return err
	}
	return nil
}

func DeleteBookById(bookId int64) error {
	err := dao.DeleteBookById(bookId)
	if err != nil {
		return err
	}
	return nil
}

func UpdateBookNums(book *model.Book) error {
	err := dao.UpdateBookNums(book)
	if err != nil {
		return err
	}
	return nil
}

func UpdateBookStatus(book *model.Book) error {
	err := dao.UpdateBookStatus(book)
	if err != nil {
		return err
	}
	return nil
}
